<?php
   
/**
 * Mapper for tlanguages
 * 
 * @author Martin Grossmann <snake.aas@gmail.com>
 * @version 1.0
 * @package Mappers
 *
 * @property string $Language shortcut of available translation. 10 chars max
 * @property string $FullName Full name of available translation. 15 chars max
 * @property string $FlagUNC Image of Flag
 * @property-read string $FlagMimeType
 * @property-read int $FlagWidth 
 * @property-read int $FlagHeight some desc
 * 
 * @entity
 * @table(name="tlanguages")
 */     
class Language {
  
  const PATH = 'images/tlanguages/';
  
  /**
   * Shortcut of available translation
   * 
   * @access private
   * @var string
   * 
   * @Id
   * @column(name="idLanguage", type="string", length=10)
   */
   private $idLanguage;
     
  /**
   * Full name of available translation
   * 
   * @access private
   * @var string
   * 
   * @column(name="FullName", type="string", length=15)
   */
   private $fullName;
   
   /**
    *
    * @access private
    * @var string 
    * 
    * @column(name="FlagUNC", type="string", length=50, nullable=true)
    */
   private $flagUNC;
     

  public function __get($name) {
  
    switch($name) {  
      case "Language": 
        return $this->idLanguage;
        break;
    
      case "FullName": 
        return $this->fullName;
        break;
      
      case "FlagUNC":
        return self::PATH.$this->flagUNC;
        break;
      
      case "FlagMimeType":
        return "image/jpeg";
        break;
      
      case "FlagWidth":
        return 16;
        break;
      
      case "FlagHeight":
        return 11;
        break;
      
      default: 
        throw new EntityException(sprintf(T_("Trying to get undefined property")." ", $name));
      
    }
  }
  
  public function __set($name, $value) {
    
    switch($name) {
      case "Language": 
        $this->idLanguage = Validations::validateString($value, 10, null, false);
        break; 

      case "FullName": 
        $this->fullName = Validations::validateString($value, 15, null, false);
        break; 
      
      case "Flag":
        $position = strpos($value, self::PATH);
        if ($position !== false) {
          $value = str_replace(self::PATH, '', $value);
        }                  
        $this->flagUNC = Validations::validateString($value, null, Validations::regexp_fileName, true);        
        break;
      
      default: 
        throw new EntityException(sprintf(T_("Trying to set undefined property")." ", $name));
    }
  }  
  
  public function __construct() {
    
  }
  
    
}